package liveData.migration.toPhoenix;

import com.alibaba.fastjson.JSONObject;
import liveData.migration.toPhoenix.entity.JobSetting;
import org.junit.Test;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

import static liveData.migration.toPhoenix.entity.ConsumerOffset.EARLIEST;

/**
 * @program: LiveDataMigrationToPhoenix
 * @description:
 * @author: sunteng
 * @create: 2020-08-12 16:20
 **/
public class JobSettingProd {

    @Test
    public void testSettings() {
        JobSetting jobSetting = new JobSetting();
        jobSetting.setParallelism(6);
        jobSetting.setTaskName("VERIFY_RESULT_PHOENIX");

        JobSetting.Sink sink = jobSetting.new Sink();
        sink.setMode("phoenix");
        sink.setPhoenixDriver("org.apache.phoenix.jdbc.PhoenixDriver");
        sink.setPhoenixTable("verify_result_phoenix");
        sink.setPhoenixUrl("jdbc:phoenix:10.10.12.215,10.10.12.216,10.10.12.129:2181:/hbase");

        jobSetting.setSink(sink);

        JobSetting.Source source = jobSetting.new Source();

        source.setOffsetFlag(EARLIEST.getOffsetFlag());
        source.setMode("kafka");
        source.setMysqlPk("id");
        source.setMysqlTable("verify_result");
        source.setPartitionParallel(3);
        source.setServer("10.10.15.82:9092");
        source.setTopic("risk.management.mysql.paydayloan.verify.result");

        jobSetting.setSource(source);

        System.out.println(JSONObject.toJSON(jobSetting));
        String settings = JSONObject.toJSONString(jobSetting);
        try (BufferedWriter bw = new BufferedWriter(new FileWriter("src\\main\\resources\\jobSetting.json", false))) {
            bw.write(settings);
            bw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
